/**
 * Created by ali on 2017/12/4.
 */
// var basePath = "http://127.0.0.1/GraduationProject";
var flag; //设置添加或修改的标识
var attrId = []; //存页面的所有id
$(function() { 
    loadData();
});

//加载数据
function loadData() {
	$.ajax({
		type : "get",
		url : basePath + "/log/listLoginLog",
		async : true,
		success : function(data) {
			if(data){
				$('#dataTable').bootstrapTable("loadByRecords",data.obj)
				.on('page-change.bs.table', function (e, number, size) {
					updateRecordsByPage (number,size);
				})
			}
		}
	});
}

/**
 * 点击下一页或者是上一页的时候进行分页
 * 
 * @param number
 *            页码
 * @param size
 *            数量
 * @returns
 */
function updateRecordsByPage(number,size){
	var page = {};
	page.size=size;
	page.current=number;
	$.ajax({
		type:"get",
		url:basePath +"/log/listLoginLog",
		data : {"page":JSON.stringify(page)},
		async:false,
		success:function(data){
			if(data){
				$('#dataTable').bootstrapTable("loadByRecords",data.obj)
			}
		}
	});
} 

//排序
function numberSort(a, b) {
    var number1 = parseFloat(a);
    var number2 = parseFloat(b);
    return(number1 > number2 ? 1 : -1);
}

/**
 * 模糊查询
 * @returns
 */
function doQuery(){
	var key = $("#keyWord").val();
	var page = {}
	page.condition={}
	page.condition.username=key;
	$.ajax({
		type : "get",
		url :basePath + "/log/listLoginLog",
		data : {"page":JSON.stringify(page),"isSearch":1},
		success : function(data) {
			if (data) {
				dataobj = data.obj.records;
				$('#dataTable').bootstrapTable("loadByRecords",dataobj);
			}
		},
		error:function (data){
			console.log(data);
		}
	});

}
  
//保存
function save() {
     
}

//取消
function cancel() {
    
}

//删除
function remove() {
	var id = $("#lid").val(); 
	console.log("id: " +id);
    $.ajax({
		type:"post",
		url:basePath +"/log/delLoginlog/" +id, 
		async:true,
		success:function(data){
				alert(data.msg);
				document.location.reload();
		},
		error: function(data){
			alert(data.msg);
			document.location.reload();
		}
	});
}
 
 
/**
 * 格式化操作栏
 * 
 * @param {Object}
 *            value
 * @param {Object}
 *            row
 * @param {Object}
 *            index
 */
function operateFormatter(value, row, index) {
	return '<a href="" style="color:#31B0D5;" data-toggle="modal" data-lid="'+row.id+'" data-target="#delModal">删除</a>';
}

/**
 * 格式化时间
 * 
 * @param {Object}
 *            value
 * @param {Object}
 *            row
 * @param {Object}
 *            index
 */
function dateFormatter(value, row, index) {
	return  (new Date(value)).Format("yyyy-MM-dd hh:mm:ss");
}
/**
 * 格式化时间
 */
Date.prototype.Format = function (fmt) { //author: tony  
    var o = {  
        "M+": this.getMonth() + 1, //月份  
        "d+": this.getDate(), //日  
        "h+": this.getHours(), //小时  
        "m+": this.getMinutes(), //分  
        "s+": this.getSeconds(), //秒  
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度  
        "S": this.getMilliseconds() //毫秒  
    };  
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
    for (var k in o)  
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));  
    return fmt;  
};
